﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Video.Application.Contract.Base;
using Video.Application.Contract.Videos;
using Video.Application.Contract.Videos.Dtos;

namespace Video.HttpApi.Host.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class VideoController : ControllerBase
    {
        private readonly IVideoService _videoService;
        public VideoController(IVideoService videoService)
        {
            _videoService = videoService;
        }
        [HttpPost]
        public async Task CreateVideoAsync(CreateVideoInput createVideoInput)
        {
             await _videoService.CreateAsync(createVideoInput);
        }
        [HttpDelete("{id}")]
        public async Task DeleteAsync(Guid id)
        {
            await _videoService.DeleteAsync(id);
        }
        [HttpDelete("Admin")]
        [Authorize(Roles ="admin")]
        public async Task AdminDeleteAsync(Guid id)
        {
            await _videoService.DeleteAsync(id);
        }
        [HttpGet("list")]
        public async Task<PageResultDto<GetVideoListDto>> GetVideoListAsync([FromQuery]GetVideoInput videoInput)
        {
            return await _videoService.GetListAsync(videoInput);
        }

        /// <summary>
        /// 创建视频分类
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        [HttpPost("VideoClassifyCreate")]
        public async Task CreateClassifyAsync(string name)
        {
            await _videoService.CreateClassifyAsync(name);
        }
        [HttpDelete("VideoClassifyDelete")]
        /// <summary>
        /// 删除视频分类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task DeleteClassifyAsyn(Guid id)
        {
            await _videoService.DeleteClassifyAsyn(id);
        }
        [HttpPut("VideoClassifyUpdate")]
        /// <summary>
        /// 修改视频分类
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task UpdateClassifyAsync(ClassifyDto dto)
        {
            await _videoService.UpdateClassifyAsync(dto);
        }
        [HttpGet("GetVideoClassifyList")]
        /// <summary>
        /// 获取分类列表
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task<List<ClassifyDto>> GetClassifyListAsync(string? name)
        {
           return await _videoService.GetClassifyListAsync(name);
        }

    }
}
